# Maintainer: Hendra Manudinata <hendra@manoedinata.com>
# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/exynos7570-j4lte_defconfig

pkgname=linux-samsung-j4lte
pkgver=3.18.140
pkgrel=0
pkgdesc="Samsung Galaxy J4 kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="samsung-j4lte"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	openssl-dev
	perl
	dtbtool-exynos
"

# Source
_repository="android_kernel_samsung_j4lte"
_commit="3649f566a23e749962b946d54a3c73e1a9305ffc"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://gitlab.com/manoedinata/$_repository/-/archive/$_commit.tar.gz
	$_config
	0001-drivers-leds-ktd2692-Guard-function-calls-under-CONF.patch
	0002-drivers-samsung-scsc-Skip-mount-point-check.patch
	0003-Update-file-proc.S.patch
	0004-drivers-usb-u_ether-Force-setting-random-MAC-address.patch
	0005-staging-samsung-sec_batt-Force-disable-low-power-cha.patch
	0006-HACK-decon_7570-Swap-red-blue-offset.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"

	# Build dt image with exynos dtbtool
	dtbTool-exynos --pagesize 2048 \
		--platform 0x50a6 \
		--subtype  0x217584da \
		-o "$_outdir/arch/$_carch/boot"/dt.img \
		$(find "$_outdir/arch/$_carch/boot/dts/" -name *.dtb)
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" \
		"$_flavor" "$_outdir"

	install -Dm644 "$_outdir/arch/$_carch/boot"/dt.img \
		"$pkgdir"/boot/dt.img
}

sha512sums="
fa8883e729c612fc9c563a003f0e24642f5199684932cc92f886feca76956094b8a2a96eaee30513f50b70f38f60b07c0e13668143061c43947f545122c70a5d  linux-samsung-j4lte-3649f566a23e749962b946d54a3c73e1a9305ffc.tar.gz
a844d6505b47f6cce06b9598a88f2ae6aa40b90390eee6af6cf5b1b60ab0ac4b77f0da5395508934914a67b773c8485a81b4081f6b4d6846df7d515a018e748b  config-samsung-j4lte.aarch64
1e42cdc37e8dffd1b557705f416d94606a61a1fe70bca259d88652f1b7f0d7ded6dc475a9a92d6bf5a1db904936d8fb8ee9a312c0f3cbf461b71472a7b459462  0001-drivers-leds-ktd2692-Guard-function-calls-under-CONF.patch
6d0603e1fbb8d7682c518694c0781292e46be42111a4be84e4e7efaf3298f9c43dfcd40806e0a9f2701c096ef8e6ab223f6e36afc36fc53d3475266b42719a84  0002-drivers-samsung-scsc-Skip-mount-point-check.patch
fde3e1dc2282ed62a2b0973d385c2deed4126ce82e350d4e069635c734e480d66876094a0f99506ee03d4d72626ad7c5755ac11cd2c1a0a1f519733cdb7b6fb3  0003-Update-file-proc.S.patch
142f682492c8020222855b9e900b22ea890dff5a88283438281d6cf7dae5a53b81de75cf02c40c1fc469fa28d3ad2f7e061522375c3f03913ed27c5bd1625dcd  0004-drivers-usb-u_ether-Force-setting-random-MAC-address.patch
da954e52d90344458f80365c7fba60a5a82a0764c54c90cb6259d9f507b00e812b410d868515eb6836837a72697d9e12e2b00d0dd234c962a32888a76db4e0cc  0005-staging-samsung-sec_batt-Force-disable-low-power-cha.patch
007c9e9a8230f12da6dc05f4043cfbd2e1e8909c2397358b71a10aef2a7c7c5139df02e8f8841342c13c72dfcf5079f070acb23768e379c073a035c70b84bef3  0006-HACK-decon_7570-Swap-red-blue-offset.patch
"
